package day23;

public class Demo06 {
	public static void main(String[] args) {
		Tick t = new Tick();
		new Thread(t).start();
		new Thread(t).start();
		new Thread(t).start();
		new Thread(t).start();
	}
}

// ------------------------------

class Tick implements Runnable {

	private static int tick = 100;

	public static /*synchronized*/ boolean sale() {
		synchronized (Tick.class) {
			if (tick > 0) {
				System.out.print(Thread.currentThread().getName());
				System.out.print(" 卖出票: " + tick--);
				System.out.println(", 剩余: " + tick);
			}
			return tick > 0;
		}
	}

	@Override
	public void run() {
		while (sale());
	}
}